#region Imported Namespaces
using System;
using Workflow.NET;
using WorFlowInterface = Workflow.NET.Engine.Interfaces;
using WorkFlowEngine = Workflow.NET.Engine;
using System.Threading;
#endregion

namespace PHSRAG.Insight21.InsightWorkFlow
{
    #region Class SetHRORejectedFlag

    public class SetHRORejectedFlag : Workflow.NET.Engine.Interfaces.IActionRun 
    {
        public SetHRORejectedFlag()
		{			
		}

        public WorFlowInterface.ActionResult Run(int executionId, int executionDetailsId, WorkFlowEngine.Context currentContext, Action currentAction, string inlinkOutput, bool retry, out string output)
        {
            output = null;
            Log logger = currentContext.log;
            try
            {
                object insightApplicationName = currentContext.Contents["insightApplicationName"];
                HumansWorkFlow.InsightApplicationName = (null == insightApplicationName) ? string.Empty : ((Content)insightApplicationName).Value.ToString();

                Thread.SetData(Thread.GetNamedDataSlot("Connections"), HumansWorkFlow.Connections);
                string valueType = (string)((Workflow.NET.Property)currentAction.Properties["ValueType"]).Value;

                if (currentContext.Variables["hrorejectflag"] != null)
                {
                    currentContext.Variables["hrorejectflag"].Value = 0;

                    if (valueType == "true")
                    {
                        currentContext.Variables["hrorejectflag"].Value = 1;
                    }                    
                }
                currentContext.SaveVariables();              
                output = "Success";
            }
            catch (Exception ex)
            {
                logger.LogMessage(ReasonConst.Error, "Unable to set hro reject flag in SetHRORejectedFlag.Run() " + ex.ToString());
                output = "Failure";
            }

            return WorFlowInterface.ActionResult.Completed;
        }

        /// <summary>
        /// Gets the web control to be displayed in the activity list for this action. No user interface is implemented for
        /// this action. So it returns null.
        /// </summary>
        /// <returns>IActivityWebUIHandler - Interface that allows an object to implement a custom document view Control.</returns>
        public virtual Workflow.NET.Interfaces.IActivityWebUIHandler GetActivityWebUIHandler()
        {
            return null;
        } 
    }



    #endregion
}
